$(function() {

	$("#start-transfer-client").linkbutton({
		onClick : function() {
			$("#start-transfer-client").linkbutton({
				disabled : true
			});
			var rows = $("#jm-client-datagrid").datagrid('getChecked');
			var value = $('#p').progressbar('getValue');
			var add = Math.ceil(100 / rows.length);
			for (var i = 0; i < rows.length; i++) {
				if (value < 100) {
					$.ajax({
						url : 'transfer-client',
						async : false,// 改为同步请求
						type : 'POST',
						data : {
							out_userId : rows[i].userId,
							in_userId : $("#client-transfer-form input[name='in_userId']:checked").val(),
							cid : rows[i].cid
						},
						success : function(r) {
							if (r.success) {
								value += add;
								$('#p').progressbar('setValue', value);
								var report = $("<label>").text("转移ID：" + rows[i].cid + " " + rows[i].type);
								var br = $("<br>");
								$("#trans-report").append(br);
								$("#trans-report").append(report);
							} else {
								$('#p').progressbar('setValue', value);
								var report = $("<label>").text("转移ID：" + rows[i].cid + " " + rows[i].type + "转移失败");
								var br = $("<br>");
								$("#trans-report").append(br);
								$("#trans-report").append(report);
							}
						}
					})

				}
				if (value >= 100) {
					$('#trans-state').text("执行完成");
					$('#trans-result').text("完成，")
					var a = $('<a>').text("请关闭窗口").click(function() {
						$("#transfer-client-result-dialog").window('close');
						$("#transfer-client-result-dialog").window('destroy');
						$("#jm-client-datagrid").datagrid('reload');
					});
					$('#trans-result').append(a);
				}
			}
			;
		}
	});

})